package com.bdqn.tour.servlet.Yml;

import com.bdqn.tour.pojo.City;
import com.bdqn.tour.pojo.PageInfo;
import com.bdqn.tour.service.CityService;
import com.bdqn.tour.service.impl.CityServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
    @WebServlet("/jdshowAll")
public class Shoservlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        //分页参数
        int pageno=1;
        if (req.getParameter("PageNo")!=null){
            pageno=Integer.parseInt(req.getParameter("PageNo"));
        }
        int pagesize = 5;
        if (req.getParameter("`PageSize`")!=null){
            pagesize=Integer.parseInt(req.getParameter("PageSize"));
        }
        //调用业务层
        CityService cityService = new CityServiceimpl();
        //获取分页数据
        List<City> show = cityService.show(pageno, pagesize);
        int count = cityService.count();
        PageInfo<City> jdshow = new PageInfo<>();
        jdshow.setCurrPageNo(pageno);
        jdshow.setPageSize(pagesize);
        jdshow.setList(show);
        jdshow.setTotals(count);
        //存储分页数据
        req.getSession().setAttribute("jdshow", jdshow);
        //转发
       req.getRequestDispatcher("houtai.jsp").forward(req,resp);

    }
}
